package com.soft.javase.day06;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class DateDemo2 {
    public static void main(String[] args) {
        System.out.println("----计算出生日期至今的天数----");

        LocalDate localDate = LocalDate.of(2001, 6, 30);
        long until = localDate.until(LocalDate.now(), ChronoUnit.DAYS);
        System.out.println("出生日期至今的天数: "+until);

        System.out.println();
        System.out.println("----当前日期三天后的日期是 (格式： 2024年10月29日 10:10:10 )----");

        LocalDateTime now = LocalDateTime.now();
        LocalDateTime threeDaysLater = now.plusDays(3);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(formatter.format(threeDaysLater));

        System.out.println();
        System.out.println("---一批食品的生产日期是：2024-5-10，保质期：180天，求过期时间---");
        LocalDate localDate1 = LocalDate.of(2024, 5, 10);
        LocalDate localDate2 = localDate1.plusDays(180);
        String str = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(localDate2);
        System.out.println("过期时间: "+str);

        System.out.println();
        System.out.println("----求上个月的第三天是星期几----");
        LocalDate today = LocalDate.now();
        LocalDate thirdDayOfLastMonth = today.minusMonths(1).withDayOfMonth(3);
        System.out.println(DateTimeFormatter.ofPattern("上个月的第三天是EEEE").format(thirdDayOfLastMonth));

        System.out.println();
        System.out.println("----找出下个月的倒数第3天是哪天----");
        LocalDate today2 = LocalDate.now();
        LocalDate lastMonth = today2.plusMonths(1);
        LocalDate lastDay = lastMonth.withDayOfMonth(lastMonth.lengthOfMonth());
        System.out.println("下个月的倒数第3天是"+lastDay.minusDays(2));

        System.out.println();
        System.out.println("-----请问今天是今年的第多少天-----");
        System.out.println("今天是今年的第"+LocalDate.now().getDayOfYear()+"天");

        System.out.println();
        System.out.println("----输入任意一个年份，得到这年的2月份有几天----");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入任意一个年份");
        int year = sc.nextInt();
        int dayOfMonth = LocalDate.of(year, 3, 1).minusDays(1).getDayOfMonth();
        System.out.println(year+"年的2月份有"+dayOfMonth+"天");



    }
}
